<template>
	<div class="ui-radio-group" :style="style" :class="classname">
		<slot></slot>
	</div>
</template>

<script>
	/*
	组件属性[
		value:当前组选中值
		style:自定义样式
		class:自定义class
		name:name属性
		rules:用于表单验证
				[
					empty:[true/false,"提示信息"],
					int:[true/false,"提示信息"],
					min:[200,"提示信息"],
					...
				],

	]
	组件自定义事件[
		change:选项发生改变时回调的父组件方法，callback(obj[当前实例])
	]
	*/
	export default{
		props:{
			name:{type:String,default:""},
            value:{type:null,default:""},
			rules:{type:Array,default:[]}
		},
		data(){
			return{
				uiType:"ui-radio-group",
			}
		},
		methods:{			
			set(obj){
				let child=this.$children;
				for(let o=0;o<child.length;o++){
					if(child[o].uiType=="ui-radio"){
						child[o]!=obj?child[o].checked=false:child[o].checked=true;
					}
				}
				this.value=obj.value;
                this.$emit('change',this);
			}
		},
        mounted(){
            this.$nextTick(function(){
				if(this.name){
				    for(let i=0;i<this.$children.length;i++){
				        this.$children[i].name=this.name;
				        if(this.$children[i].value==this.value){
                            this.$children[i].checked=true;
						}
					}
				}
			});
		}
	}
</script>
